/*
 * MembersUpdate.java
 *
 * Created on November 15, 2008, 7:39 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Members.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jollylengkono.skripsi.Members.form.MembersUpdateForm;
import jollylengkono.skripsi.dao.DepartmentsDao;
import jollylengkono.skripsi.dao.DivisionsDao;
import jollylengkono.skripsi.dao.GroupsDao;
import jollylengkono.skripsi.dao.MembersDao;
import jollylengkono.skripsi.model.Departments;
import jollylengkono.skripsi.model.Divisions;
import jollylengkono.skripsi.model.Groups;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author JollkY
 */
public class MembersUpdate extends Action {
    private String FORWARD;
    private int STATE;
    
    /** Creates a new instance of MembersUpdate */
    public MembersUpdate() {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        MembersUpdateForm memberForm = (MembersUpdateForm) form;
        Members members = new Members();
        members.setDepartment((Departments) new DepartmentsDao().read(memberForm.getIdDepartment()));
        members.setDivision((Divisions) new DivisionsDao().read(memberForm.getIdDivision()));
        members.setEmail(memberForm.getEmail());
        members.setFirstName(memberForm.getFirstName());
        members.setGroup((Groups) new GroupsDao().read(memberForm.getIdGroups()));
        members.setId(memberForm.getId());
        members.setLastActivity(memberForm.getLastActivity());
        members.setLastName(memberForm.getLastName());
        members.setPassword(memberForm.getPassword());
        members.setStatus(memberForm.getStatus());
        members.setUsername(memberForm.getUsername());
        this.STATE = new MembersDao().update(members);
        if (this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="fail";
        }
        return mapping.findForward(FORWARD);
    }
}
